<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/9/18
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../include/head.jsp">
    <jsp:param name="title" value="服务续租"/>
</jsp:include>

<jsp:include page="../include/admin_header.jsp"/>

<jsp:include page="../include/admin_sidebar.jsp"/>


<div class="content-wrapper content-wrapper-bg">
    <section class="content-header">
        <h4 class="page-title"><spring:message code="label.service.postpone"/></h4>
    </section>
    <section class="content">
        <div class="row" style="margin-right:0;margin-left: 0">
            <div class="col-md-8" style="padding-left: 0;padding-right: 0;">
                <div style="margin-right: 20px">
                    <div class="box box-primary table-header-line">
                        <div class="box-body" style="min-height:636px">
                            <div class="form-horizontal">
                                <div style="padding-top: 35px">
                                    <div style="width: 50%;display: inline-block;vertical-align:top;">
                                        <div style="text-align: right;margin-right:20px;"><spring:message code="label.tenant.create.service"/>:</div>
                                    </div><!--
                             --><div class="sie-flex-box" style="width: 50%;display: inline-block;text-align: left;line-height: 15px;margin-top: 0">
                                        <c:forEach var="server" items="${services}">
                                            <c:if test="${server.getEnabled()=='1'}">
                                                <div class="sie-flex-item item-access <c:if test="${serviceId.indexOf(server.getService_id()) > -1}">
                                                item-checked </c:if>" data-value="${server.getService_id()}" style="padding-bottom: 10px">
                                                    <i class="sie-checkbox checked"></i><span>${server.getService_name()}</span>
                                                </div>
                                            </c:if>
                                        </c:forEach>
                                        <scan><spring:message code="label.service.postpone.add"/><select id="date">
                                            <option value="0">0</option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                            <option value="6">6</option>
                                            <option value="7">7</option>
                                            <option value="8">8</option>
                                            <option value="9">9</option>
                                            <option value="10">10</option>
                                            <option value="11">11</option>
                                            <option value="12">12</option>
                                        </select><spring:message code="label.service.month"/>
                                        </scan>
                                    </div>
                                    <div style="text-align: center;margin-top: 30px;">
                                        <a id="submit" class="solid-button-blue" style="width: 80px"
                                           href="javascript:;"><spring:message code="label.admin.confirm"/> </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4" style="padding-left:0;padding-right: 0">
                <div class="box box-primary table-header-line">
                    <div class="box-body" style="min-height:636px">
                        <div class="form-horizontal">
                            <div style="padding-top: 35px;">
                                <h4 style="text-align: center;margin-top: 0;font-weight: 600;margin-bottom: 20px;">
                                   <spring:message code="label.service.property"/></h4>

                                <div class="form-group" style="margin-right: 0;margin-left: 0;">
                                    <label name="name" class="col-md-4"
                                           style="text-align: right;font-weight: 400"><spring:message code="label.tenant.service.tenant.name"/>:</label>

                                    <div class="col-md-8">${tenant.getTenantName()}</div>
                                    <input id="tenantId" class="col-md-6" hidden="hidden"
                                           value="${tenant.getTenantId()}">
                                </div>
                                <div class="form-group" style="margin-right: 0;margin-left: 0;">
                                    <label name="name" class="col-md-4"
                                           style="text-align: right;font-weight: 400"><spring:message code="label.tenant.create.address"/>:</label>

                                    <div class="col-md-8">${tenant.getAddress()}</div>
                                </div>
                                <div class="form-group" style="margin-right: 0;margin-left: 0;">
                                    <label name="name" class="col-md-4"
                                           style="text-align: right;font-weight: 400"><spring:message code="label.tenant.create.contact"/>:</label>

                                    <div class="col-md-8">${tenant.getContact()}</div>
                                </div>
                                <div class="form-group" style="margin-right: 0;margin-left: 0;">
                                    <label name="name" class="col-md-4"
                                           style="text-align: right;font-weight: 400"><spring:message code="label.tenant.create.phone"/>:</label>

                                    <div class="col-md-8">${tenant.getTelephone()}</div>
                                </div>
                                <div class="form-group" style="margin-right: 0;margin-left: 0;">
                                    <label name="name" class="col-md-4"
                                           style="text-align: right;font-weight: 400"><spring:message code="label.tenant.register"/>:</label>

                                    <div class="col-md-8">${deviceCount}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<jsp:include page="../include/foot.jsp"/>
<script>
    $(document).ready(function () {
        $(".item-access").bind("click",function(){
            $(this).hasClass("item-checked") ? $(this).removeClass("item-checked") : $(this).addClass("item-checked");
        });
        $("#submit").click(function () {
            var serviceArr = [];
            var checked = $(".item-checked");
            $.each(checked,function(i,service){
                serviceArr.push($(service).data("value"));
            });

            $.ajax({
                type: "post",
                url: "/admin/api/v1/service/extend",
                data: {
                    tenantId: $("#tenantId").val(),
                    services: serviceArr,
                    date: $("#date").find("option:selected").val()
                },
                success: function () {
                    swal({
                        title: '<spring:message code="label.success"/>',
                        text: "",
                        type: "success",
                        showCancelButton: false,
                        showConfirmButton: true,
                        confirmButtonText: '<spring:message code="label.admin.confirm"/>',
                        cancelButtonText: "",
                        animation: "slide-from-top"
                    }, function () {
                        window.location.replace("/admin/service/manage#serviceManage");
                    });
                },
                fail: function () {
                    swal("Error!", "", "error");
                }
            })
        });
    });
</script>
